<?php

namespace App\Console;

use App\Common\Console\ConvertCallbackCommand;
use App\Common\Console\Queue\QueueClickCommand;
use App\Common\Console\RedisCallCommand;
use App\Common\Helpers\Functions;
use App\Console\Commands\Ocean\OceanMaterialPromotionSyncCommand;
use App\Console\Commands\Ocean\OceanSyncProjectCommand;
use App\Console\Commands\Ocean\OceanSyncPromotionCommand;
use App\Console\Commands\Ocean\Report\OceanSyncAccountReportCommand;
use App\Console\Commands\Ocean\Report\OceanSyncMaterialReportCommand;
use App\Console\Commands\Ocean\Report\OceanSyncPromotionReportCommand;
use App\Console\Commands\SyncChannelProjectCommand;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // redis
        RedisCallCommand::class,

        // 队列
        QueueClickCommand::class,

        // 巨量信息同步
        OceanSyncProjectCommand::class,
        OceanSyncPromotionCommand::class,

        // 巨量报表同步
        OceanSyncAccountReportCommand::class,
        OceanSyncPromotionReportCommand::class,
        OceanSyncMaterialReportCommand::class,

        // 巨量素材广告同步
        OceanMaterialPromotionSyncCommand::class,

        // 同步渠道-项目关联
        SyncChannelProjectCommand::class,

        // 转化回传
        ConvertCallbackCommand::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // 队列
        $schedule->command('queue:click')->cron('* * * * *');

        // 同步渠道-项目关联
        $schedule->command('sync_channel_project --date=today')->cron('*/2 * * * *');

        // 统计广告转化回传
        //$schedule->command('stat_promotion_convert --date=today')->cron('* * * * *');
        //$schedule->command('stat_promotion_convert --date=yesterday')->cron('0-10 0,2 * * *');

        // 正式
        if(Functions::isProduction()){
            // 转化上报
            $schedule->command('convert_callback')->cron('* * * * *');

            // 同步素材-广告关联
            $schedule->command('ocean:material_promotion_sync --date=today')->cron('*/20 * * * *');

            // 巨量项目同步
            $schedule->command('ocean:sync_project --update_date=today')->cron('*/2 * * * *');
            $schedule->command('ocean:sync_project --update_date=yesterday --key_suffix=yesterday')->cron('15-20 2 * * *');

            // 巨量广告同步
            $schedule->command('ocean:sync_promotion --update_date=today --create_log=1')->cron('*/2 * * * *');
            $schedule->command('ocean:sync_promotion --update_date=today --delivery_mode=procedural --create_log=1  --key_suffix=procedural')->cron('*/2 * * * *');
            $schedule->command('ocean:sync_promotion --update_date=yesterday --create_log=1 --key_suffix=yesterday')->cron('15-20 1 * * *');
            $schedule->command('ocean:sync_promotion --update_date=yesterday --delivery_mode=procedural --create_log=1 --key_suffix=yesterday_procedural')->cron('15-20 2 * * *');

            // 巨量账户报表同步
            $schedule->command('ocean:sync_account_report --date=today --has_history_cost=1 --key_suffix=has_history_cost')->cron('*/2 * * * *');
            $schedule->command('ocean:sync_account_report --date=today --run_by_new_account=1 --key_suffix=run_by_new_account')->cron('*/3 * * * *');
            $schedule->command('ocean:sync_account_report --date=today')->cron('15 * * * *');
            $schedule->command('ocean:sync_account_report --date=yesterday --key_suffix=yesterday')->cron('15-20 10 * * *');

            // 巨量广告报表同步
            $schedule->command('ocean:sync_promotion_report --date=today --has_history_cost=1 --multi_chunk_size=3')->cron('*/2 * * * *');
            $schedule->command('ocean:sync_promotion_report --date=yesterday --key_suffix=yesterday')->cron('35-40 9,14 * * *');

            // 巨量素材报表同步
            $schedule->command('ocean:sync_material_report --date=today --key_suffix=today --has_history_cost=1')->cron('*/10 * * * *');
            $schedule->command('ocean:sync_material_report --date=yesterday --key_suffix=yesterday --has_history_cost=1')->cron('15-20 10,12,15 * * *');
        }
    }
}
